import { CopyControllerBase } from "./CopyControllerBase";
import { IClean } from "../../../../../com/gengine/core/IClean";
import { MessageBlock } from "../../../../../Framework/MQ/MessageBlock";
import { SSeqPlayerItem } from "../../../../../Message/Public/SSeqPlayerItem";
import { SCrossSecretBossList } from "../../../../../Message/Public/SCrossSecretBossList";
import { Language } from "../../../../../extend/language/Language";
import { SCrossSecretCopyInfo } from "../../../../../Message/Public/SCrossSecretCopyInfo";
import { ClockManager } from "../../../manager/ClockManager";
import { DataEvent } from "../../../events/DataEvent";
import { SEntityInfo } from "../../../../../Message/BroadCast/SEntityInfo";
import { GameConst } from "../../../../component/gconst/GameConst";
import { SystemSetter } from "../../system/SystemSetter";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { EventName } from "../../../mvc/EventName";
import { GameProxy } from "../../../mvc/GameProxy";
import { CrossAryadevaSecretCopyView } from "../crossAryadevaSecretCopy/CrossAryadevaSecretCopyView";
import { NetDispatcher } from "../../../../mvc/core/NetDispatcher";
import { EPublicCommand } from "../../../../../Message/Command/EPublicCommand";
import { TCopy } from "../../../../../Message/Db/Tables/TCopy";
import { MsgManager } from "../../../manager/MsgManager";
type int = number;
//class CrossAryadevaSecretCopyController
    
    export  class CrossAryadevaSecretCopyController extends CopyControllerBase implements IClean
    {
        constructor()
        {
            super();
            this._crossSecretRewardItems = [];
            return;
        }

        /* internal  */onSecretItemList(arg1: MessageBlock): void
        {
            var loc1=arg1.messageBase as SSeqPlayerItem;
            cache.copy.crossASCopyItems = loc1.playerItem;
            this.crossAryadevaSecretCopyView.updateItems();
            return;
        }

        /* internal  */onCrossSecretRewardItems(arg1: MessageBlock): void
        {
            var loc1=arg1.messageBase as SSeqPlayerItem;
            this._crossSecretRewardItems = loc1.playerItem;
            this.crossAryadevaSecretCopyView.updataAwardInfo(this._crossSecretRewardItems);
            return;
        }

        /* internal  */onCrossSecretBossList(arg1: MessageBlock): void
        {
            var loc2=0;
            var loc3=0;
            var loc4=0;
            var loc5=0;
            var loc6=0;
            var loc7=null;
            var loc1=arg1.messageBase as SCrossSecretBossList;
            if (loc1 && loc1.bossInfo) 
            {
                loc2 = loc1.bossInfo[2163002] > 0 ? 1 : 0;
                loc3 = loc1.bossInfo[2163001] > 0 ? 1 : 0;
                loc4 = loc1.bossInfo[2163003] > 0 ? 1 : 0;
                loc5 = loc1.bossInfo[2163004] > 0 ? 1 : 0;
                loc6 = loc1.bossInfo[2163005] > 0 ? 1 : 0;
                loc7 = Language.getStringByParam(27601, loc2, loc3, loc4, loc5, loc6);
                this.crossAryadevaSecretCopyView.updataKillBossInfo(loc7);
                if (loc2 + loc3 + loc4 + loc5 + loc6 >= 5) 
                {
                    this.crossAryadevaSecretCopyView.stopLeftTime();
                }
                if (loc2 + loc3 + loc4 + loc5 + loc6 >= 5 && this._crossSecretRewardItems.length > 0) 
                {
                    this.crossAryadevaSecretCopyView.rewardViewShow(this._crossSecretRewardItems);
                }
            }
            return;
        }

        /* internal  */onCrossSecretCopyInfo(arg1: MessageBlock): void
        {
            var loc2=null;
            var loc1=arg1.messageBase as SCrossSecretCopyInfo;
            if (loc1 && loc1.endDt) 
            {
                loc2 = ClockManager.instance.nowDate;
                this.crossAryadevaSecretCopyView.updateLeftTime(int((loc1.endDt.time - loc2.time) / 1000));
            }
            return;
        }

        /* internal  */showGuide(arg1: DataEvent): void
        {
            var loc1=arg1.data as SEntityInfo;
            if (loc1 && this._crossAryadevaSecretCopyView) 
            {
                if (loc1.code == GameConst.CrossSecretGuideBossCode) 
                {
                    if (cache.clientSettingCache.isFirstCrossAryadevaSecretCopy) 
                    {
                        cache.clientSettingCache.isFirstCrossAryadevaSecretCopy = false;
                        SystemSetter.systemGuideSetterInfo.setSystemInfo("isFirstCrossAryadevaSecretCopy", false);
                        Dispatcher.dispatchEvent(new DataEvent(EventName.SaveGuideSystemSetter));
                    }
                    cache.copy.guideStep = 1;
                    this.crossAryadevaSecretCopyView.addGuide();
                    Dispatcher.removeEventListener(EventName.Scene_AddEntity, this.showGuide);
                }
            }
            return;
        }

        /* internal  */addSecondStepGuide(arg1: DataEvent): void
        {
            if (cache.copy.guideStep == 1 && this._crossAryadevaSecretCopyView) 
            {
                cache.copy.guideStep = 2;
                this.crossAryadevaSecretCopyView.addSecondStepGuide();
                Dispatcher.removeEventListener(EventName.CrossAryadevaSecretCopyAddGuideStepSecond, this.addSecondStepGuide);
            }
            return;
        }

        /* internal  */addThirdlyStepGuide(arg1: DataEvent): void
        {
            if (cache.copy.guideStep == 2 && this._crossAryadevaSecretCopyView) 
            {
                cache.copy.guideStep = 0;
                this.crossAryadevaSecretCopyView.addThirdlyStepGuide();
                Dispatcher.removeEventListener(EventName.CrossAryadevaSecretCopyAddGuideStepThirdly, this.addThirdlyStepGuide);
            }
            return;
        }

        /* internal  */onGetRewardHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data["times"] as int;
            GameProxy.copy.getCrossSecretItem(loc1);
            return;
        }

        /* internal  */onGetRewardSuccessHandler(arg1: DataEvent): void
        {
            if (this._crossAryadevaSecretCopyView) 
            {
                this.crossAryadevaSecretCopyView.rewardViewHide();
            }
            return;
        }

        /* internal  */showRewardView(arg1: DataEvent): void
        {
            var loc1=arg1.data.showReturnBtn;
            this.crossAryadevaSecretCopyView.rewardViewShow(this._crossSecretRewardItems, loc1);
            return;
        }

        /* internal  */leaveCrossAryadevaSecretCopy(arg1: DataEvent): void
        {
            GameProxy.copy.leftGroup_async();
            return;
        }

        public get crossAryadevaSecretCopyView(): CrossAryadevaSecretCopyView
        {
            if (this._crossAryadevaSecretCopyView == null) 
            {
                this._crossAryadevaSecretCopyView = new CrossAryadevaSecretCopyView();
            }
            return this._crossAryadevaSecretCopyView;
        }

        protected /* override */ initServer(): void
        {
            NetDispatcher.addCmdListener(EPublicCommand._ECmdPublicCrossSecretItemList, this.onSecretItemList);
            NetDispatcher.addCmdListener(EPublicCommand._ECmdPublicCrossSecretRewardItems, this.onCrossSecretRewardItems);
            NetDispatcher.addCmdListener(EPublicCommand._ECmdPublicCrossSecretBossList, this.onCrossSecretBossList);
            NetDispatcher.addCmdListener(EPublicCommand._ECmdPublicCrossSecretCopyInfo, this.onCrossSecretCopyInfo);
            return;
        }

        protected /* override */ addListener(): void
        {
            Dispatcher.addEventListener(EventName.Scene_AddEntity, this.showGuide);
            if (cache.clientSettingCache.isFirstCrossAryadevaSecretCopy) 
            {
                Dispatcher.addEventListener(EventName.CrossAryadevaSecretCopyAddGuideStepSecond, this.addSecondStepGuide);
                Dispatcher.addEventListener(EventName.CrossAryadevaSecretCopyAddGuideStepThirdly, this.addThirdlyStepGuide);
            }
            Dispatcher.addEventListener(EventName.GetCopyMultiplicityReward, this.onGetRewardHandler);
            Dispatcher.addEventListener(EventName.GetMultiplicityRewardSuccess, this.onGetRewardSuccessHandler);
            Dispatcher.addEventListener(EventName.LeaveCrossAryadevaSecretCopyAndShowRewardView, this.showRewardView);
            Dispatcher.addEventListener(EventName.LeaveMultiplicityRewardCopy, this.leaveCrossAryadevaSecretCopy);
            if (!NetDispatcher.hasCmdListener(EPublicCommand._ECmdPublicCrossSecretItemList)) 
            {
                NetDispatcher.addCmdListener(EPublicCommand._ECmdPublicCrossSecretItemList, this.onSecretItemList);
            }
            if (!NetDispatcher.hasCmdListener(EPublicCommand._ECmdPublicCrossSecretRewardItems)) 
            {
                NetDispatcher.addCmdListener(EPublicCommand._ECmdPublicCrossSecretRewardItems, this.onCrossSecretRewardItems);
            }
            if (!NetDispatcher.hasCmdListener(EPublicCommand._ECmdPublicCrossSecretBossList)) 
            {
                NetDispatcher.addCmdListener(EPublicCommand._ECmdPublicCrossSecretBossList, this.onCrossSecretBossList);
            }
            if (!NetDispatcher.hasCmdListener(EPublicCommand._ECmdPublicCrossSecretCopyInfo)) 
            {
                NetDispatcher.addCmdListener(EPublicCommand._ECmdPublicCrossSecretCopyInfo, this.onCrossSecretCopyInfo);
            }
            return;
        }

        protected /* override */ removeListener(): void
        {
            Dispatcher.removeEventListener(EventName.Scene_AddEntity, this.showGuide);
            Dispatcher.removeEventListener(EventName.LeaveCrossAryadevaSecretCopyAndShowRewardView, this.showRewardView);
            Dispatcher.removeEventListener(EventName.LeaveMultiplicityRewardCopy, this.leaveCrossAryadevaSecretCopy);
            Dispatcher.removeEventListener(EventName.CrossAryadevaSecretCopyAddGuideStepSecond, this.addSecondStepGuide);
            Dispatcher.removeEventListener(EventName.CrossAryadevaSecretCopyAddGuideStepThirdly, this.addThirdlyStepGuide);
            Dispatcher.removeEventListener(EventName.GetCopyMultiplicityReward, this.onGetRewardHandler);
            Dispatcher.removeEventListener(EventName.GetMultiplicityRewardSuccess, this.onGetRewardSuccessHandler);
            NetDispatcher.removeCmdListener(EPublicCommand._ECmdPublicCrossSecretItemList, this.onSecretItemList);
            NetDispatcher.removeCmdListener(EPublicCommand._ECmdPublicCrossSecretRewardItems, this.onCrossSecretRewardItems);
            NetDispatcher.removeCmdListener(EPublicCommand._ECmdPublicCrossSecretBossList, this.onCrossSecretBossList);
            NetDispatcher.removeCmdListener(EPublicCommand._ECmdPublicCrossSecretCopyInfo, this.onCrossSecretCopyInfo);
            return;
        }

        public /* override */ stageResize(): void
        {
            if (this._crossAryadevaSecretCopyView) 
            {
                this.crossAryadevaSecretCopyView.stageResize();
                this.crossAryadevaSecretCopyView.updatePosition();
            }
            return;
        }

        public /* override */ enterCopy(arg1: TCopy): void
        {
            super.enterCopy(arg1);
            Dispatcher.dispatchEvent(new DataEvent(EventName.ShowGameMainUI, false));
            Dispatcher.dispatchEvent(new DataEvent(EventName.TaskTrackShowOrHide, false));
            this.crossAryadevaSecretCopyView.show();
            this.crossAryadevaSecretCopyView.updateItems();
            this.stageResize();
            MsgManager.showTaskTarget(Language.getString(27609), 10);
            return;
        }

        public get CrossSecretRewardItemsNum(): int
        {
            return this._crossSecretRewardItems.length;
        }

        public /* override */ leaveCopy(): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.ShowGameMainUI, true));
            Dispatcher.dispatchEvent(new DataEvent(EventName.TaskTrackShowOrHide, true));
            this.clean();
            return;
        }

        public clean(): void
        {
            if (this._crossAryadevaSecretCopyView && this.crossAryadevaSecretCopyView.parent) 
            {
                this.crossAryadevaSecretCopyView.hide();
                this.crossAryadevaSecretCopyView.clean();
                this._crossAryadevaSecretCopyView = null;
                cache.copy.crossASCopyItems = [];
                this._crossSecretRewardItems = [];
            }
            return;
        }

        /* internal */ /* var */_crossAryadevaSecretCopyView: CrossAryadevaSecretCopyView;

        /* internal */ /* var */_crossSecretRewardItems: Array<any>;
    }
